const config = require('../../config/index')
const { wxRequest } = require('../../utils/util')

Page({
  /**
   * 页面的初始数据
   */
  data: {
    appSeqno:'',
    appType:'',
    appDt:'',
    appTerm:'',
    aprvdAmt:'',
    dealStatCdDesc: '',
    dealStatCd: '',
    licenseCode:'',
    busiName:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const { appSeqno,appDt,appTerm,aprvdAmt,dealStatCdDesc,dealStatCd,licenseCode,busiName } = options
    this.setData({
      appSeqno,
      appDt: appDt.replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3"),
      appTerm,
      aprvdAmt,
      dealStatCdDesc,
      dealStatCd,
      licenseCode,
      busiName
    })
  },
  handleOpenDialog(){
    const that = this
    const { appSeqno, busiName, licenseCode} = that.data
    wxRequest({
      url: `${config.baseUrl}/apply/tax`,
      method: 'POST',
      data: {
        appNo: appSeqno,
        taxpayerIdntfno: licenseCode,
        corpNm: busiName
      },
      invalidCb(){
        that.handleOpenDialog()
      },
      success(res){
        console.log('res',res);
        wx.navigateTo({
          url: `/pages/otherWeb/index?url=${encodeURIComponent(res.data.data.urlAddr)}`,
        })
      }
    })
  },
})